Skip to content

Read evaluate_js results with session.evaluate_js() - #3

Merged
giordano-lucas merged 1 commit into
mainfrom
t3code/evaluate-js-helper
Aug 25, 2026
Merged

Read evaluate_js results with session.evaluate_js()#3
giordano-lucas merged 1 commit into
mainfrom
t3code/evaluate-js-helper

Conversation

@giordano-lucas

Copy link
Copy Markdown
Member

What

arxiv-paper-finder (Python) carried three helpers — json_from_execution_result, coerce_json_dict, parse_json_object, ~60 lines — whose only job was to dig JSON out of an ExecutionResult whose shape the caller couldn't rely on: try .data, then .data.structured, then .data.markdown, then .message, then eight more candidate keys, then a brace-matching fallback parser.

session.evaluate_js(code) (nottelabs/notte#909) returns the evaluated value as a str — objects as JSON — so the read is just:

raw = session.evaluate_js(code)
data = json.loads(raw)

All three helpers are deleted (+8 / −69), along with a now-unused re import. A failing script also reports better: it raises with the actual JavaScript error instead of surfacing as "Could not parse evaluate_js result: <envelope repr>".

Verification

Run against staging with a released-equivalent SDK: --result-index 2 completes end to end — both evaluate_js call sites (recent-list read, article open) succeed and the PDF downloads.

Not touched

  • The TypeScript template (ts/downloads-files/arxiv-paper-finder) keeps session.execute({type: "evaluate_js"})evaluate_js() is a Python SDK addition; the JS SDK has no equivalent yet.
  • The READMEs say "Uses evaluate_js to …", which describes the capability and stays accurate.

Gate

Needs the notte-sdk release containing nottelabs/notte#909 — merge once that's on PyPI, since templates run against the released SDK.

🤖 Generated with Claude Code

The template carried three helpers - json_from_execution_result,
coerce_json_dict and parse_json_object, ~60 lines - whose only job was
to dig JSON out of an ExecutionResult whose shape the caller could not
rely on: try .data, then .data.structured, then .data.markdown, then
.message, then eight more candidate keys, then a brace-matching
fallback parser.

session.evaluate_js(code) returns the evaluated value as a string
(objects as JSON), so the read is json.loads(...) and all three helpers
are dead. A failing script now raises with the actual JavaScript error
instead of surfacing as "Could not parse evaluate_js result".

Verified against staging: --result-index 2 runs end to end and
downloads the PDF.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@giordano-lucas
giordano-lucas merged commit 00e31c7 into main Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant